﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using BigStamp.Entity;

namespace BigStamp
{
    /// <summary>
    /// Interaction logic for FormWindow.xaml
    /// </summary>
    public partial class FormWindow : Window
    {
        public FormWindow()
        {
            InitializeComponent();
        }

        

        private void btnSaveForm_Click(object sender, RoutedEventArgs e)
        {
            if (Vaildate()==true)
            {
                Utility.AddForm(
                    txtDestCity.Text,
                    txtDestAddr.Text,
                    comboSrc.Text,
                    txtSrcAddr.Text,
                    txtSrcTel.Text,
                    txtDestName.Text,
                    txtDestTel.Text,
                    txtDestTitle.Text,
                    txtDestZip.Text,
                    txtFormNum.Text);
                    
                //Utitiy.AddForm(txtDestCity,txtDestAddr,txtDest,txtSrcAddr,txtSrc,

                txtDestCity.Text = string.Empty;
                txtDestAddr.Text = string.Empty;
                txtDestName.Text = string.Empty;
                txtDestTel.Text = string.Empty;
                txtDestTitle.Text = string.Empty;
                txtDestZip.Text = string.Empty;
                txtFormNum.Text = string.Empty;
            }
        }

        private bool Vaildate() 
        {
            if (txtDestName.Text.Length>0&&
                txtDestAddr.Text.Length>0&&
                txtDestCity.Text.Length>0&&
                txtDestTel.Text.Length>0&&
                txtDestZip.Text.Length>0)
            {
                return true;
            }
            return false;
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            comboSrc.ItemsSource = Utility.BigStampDatabase.Users;
            comboSrc.DisplayMemberPath = "ScreenName";
            if (Utility.BigStampDatabase.Users.Count>0)
            {
                comboSrc.SelectedIndex = 0;
            }
            
        }

        private void comboSrc_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            UserWindow userForm = new UserWindow();
            userForm.ShowDialog();
        }

        private void comboSrc_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            txtSrcAddr.Text = ((User)comboSrc.SelectedItem).Address;
            txtSrcTel.Text=((User)comboSrc.SelectedItem).Tel;
        }
    }
}
